/**
 * Copyright (c) 2010-2011 Pierre LABATUT
 *
 * This file is part of multiple-track-player project.
 *
 * multiple-track-player is free software: you can redistribute it and/or modify it
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or <http://code.google.com/p/multiple-track-player/>.
 */
package multitrack.preload;

import java.util.ArrayList;
import java.util.List;
import javax.swing.JApplet;
import javax.swing.SwingUtilities;

/**
 * Main entry point to run the player as an applet.
 * the applet should have parameters named track01 up to track99 set with URL
 * of a WAV, AIF or MP3 file.
 * The first missing track entry makes the other one not to be considered.
 * 
 * @author Pierre LABATUT
 */
public class MainApplet extends JApplet {

    @Override
    public void init() {
        final List<String> audios = new ArrayList<String>();
        for (int n = 1; n < 100; n++) {
            String propName = String.format("track%1$02d", n);
            String propValue = getParameter(propName);
            if (propValue == null) {
                break;
            }
            // Setup the monitored audio frame stream            
            audios.add(propValue);

        }

        SwingUtilities.invokeLater(new Runnable() {

            @Override
            public void run() {
                AudioPlayerView.setSystemLookAndFeel();
                final AudioPlayerView apv = new AudioPlayerView();
                add(apv);
                validate(); // Refresh layout
                AudioPlayer.initialize(apv, audios);
            }
        });

    }
}